package com.liyuci.core.thymeleaf.eleondialect;

import com.liyuci.core.thymeleaf.eleondialect.attribute.ClassAttributeTagProcessor;
import com.liyuci.core.thymeleaf.eleondialect.attribute.IdAttributeTagProcessor;
import com.liyuci.core.thymeleaf.eleondialect.attribute.NameAttributeTagProcessor;
import com.liyuci.core.thymeleaf.eleondialect.attribute.StyleAttributeTagProcessor;
import com.liyuci.core.thymeleaf.eleondialect.attribute.TypeAttributeTagProcessor;
import com.liyuci.core.thymeleaf.eleondialect.attribute.ValueAttributeTagProcessor;
import com.liyuci.core.thymeleaf.eleondialect.element.SelectElementTagProcessor;
import com.liyuci.core.thymeleaf.eleondialect.element.TextareaElementTagProcessor;

import java.util.LinkedHashSet;
import java.util.Set;

import org.springframework.stereotype.Component;
import org.thymeleaf.dialect.AbstractProcessorDialect;
import org.thymeleaf.processor.IProcessor;
import org.thymeleaf.standard.StandardDialect;
import org.thymeleaf.standard.processor.StandardXmlNsTagProcessor;
import org.thymeleaf.templatemode.TemplateMode;

/**
 * thymeleaf自定义标签处理器
 * @author liyuci
 * @date 2018-02-05 13:56:27
 */
@Component
public class EleonDialect extends AbstractProcessorDialect {

	//定义方言名称
	private static final String DIALECT_NAME = EleonDialect.class.getSimpleName();
	//方言的前缀
	private static final String PREFIX = "eleon";
	
	public EleonDialect()
	{
		super(DIALECT_NAME, PREFIX, StandardDialect.PROCESSOR_PRECEDENCE);
	}

	@Override
	public Set<IProcessor> getProcessors(final String dialectPrefix)
	{
		LinkedHashSet<IProcessor> processors = new LinkedHashSet<IProcessor>();
		//添加自定义的标签处理器
        processors.add(new SelectElementTagProcessor(dialectPrefix));
        processors.add(new TextareaElementTagProcessor(dialectPrefix));
        
        //添加自定义标签属性处理器
        processors.add(new NameAttributeTagProcessor(dialectPrefix));
        processors.add(new IdAttributeTagProcessor(dialectPrefix));
        processors.add(new ValueAttributeTagProcessor(dialectPrefix));
        processors.add(new TypeAttributeTagProcessor(dialectPrefix));
        processors.add(new ClassAttributeTagProcessor(dialectPrefix));
        processors.add(new StyleAttributeTagProcessor(dialectPrefix));
        processors.add(new StandardXmlNsTagProcessor(TemplateMode.HTML, dialectPrefix));
        return processors;
	}

}
